﻿/**

 * Copyright (c) 2015-2017, FastDev 刘强 (fastdev@163.com).

 *

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *      http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */


using Newtonsoft.Json;
using OF.ILModifier.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestConsole;

namespace InjectedLibs
{
    public class InjectedWrap
    {
        public static void OnException(ParamContainer container, Exception ex)
        {

        }

        public static string WrapStatFuncStatReplace(TestEntity t2)
        {
            Console.WriteLine("in WrapStatFuncStatReplace!");
            return WrapStatFuncStatReplace(t2);
        }

        public void VirtualCallReplaced()
        {
            Console.WriteLine("in InjectedWrap.VirtualCallReplaced");
            try
            {
                Console.WriteLine("begin try");
                VirtualCallReplaced();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Trace Error:" + ex.ToString());
                throw;
            }
        }


        public void WrapInstActionInstReplaced(TestEntity entity)
        {
            Console.WriteLine("in WrapInstActionInstReplaced");
            try
            {
                Console.WriteLine("begin try");
                WrapInstActionInstReplaced(entity);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Trace Error:" + ex.ToString());
                throw;
            }
        }

        public static void WrapActionReplace(TestEntity entity)
        {
            try
            {
                Console.WriteLine("begin try");
                WrapActionReplace(entity);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Trace Error:" + ex.ToString());
                throw;
            }
        }

        public static outT WrapStatGenActionStatGenReplacedFunc<InT, outT>(InT t2)
        {
            Console.WriteLine("in WrapStatGenActionStatGenReplacedFunc!");
            return WrapStatGenActionStatGenReplacedFunc<InT, outT>(t2);
        }

        public string WrapInstFuncInstReplace(TestEntity t2)
        {
            Console.WriteLine("in WrapInstFuncInstReplace!");
            return WrapInstFuncInstReplace(t2);
        }


        public outT WrapInstGenFuncInstGenReplace<InT, outT>(InT t2)
        {
            Console.WriteLine("in WrapInstGenFuncInstGenReplace!");
            return WrapInstGenFuncInstGenReplace<InT, outT>(t2);
        }


        public static void Before(ParamContainer param)
        {
            Console.WriteLine("Before call!" + JsonConvert.SerializeObject(param.ParamList));
        }

        public static void After(ParamContainer param)
        {
            Console.WriteLine("After call!" + JsonConvert.SerializeObject(param.ParamList));
        }

        public void WrapInstGenActionInstGenReplaced<IT1>(IT1 t)
        {
            try
            {
                Console.WriteLine("begin try");
                WrapInstGenActionInstGenReplaced(t);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Trace Error:" + ex.ToString());
                throw;
            }
        }

        public static void RunWrapStatGenFuncStatGenReplace<IT1>(IT1 t)
        {
            try
            {
                Console.WriteLine("begin try");
                RunWrapStatGenFuncStatGenReplace(t);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Trace Error:" + ex.ToString());
                throw;
            }
        }
    }
}
